from tortoise import fields
from .base import TimestampMixin

class Chapter(TimestampMixin):
    """章节模型"""
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=100, description="章节名称")
    order = fields.IntField(description="章节顺序")
    description = fields.TextField(null=True, description="章节描述")
    document = fields.ForeignKeyField(
        'models.Document', related_name='chapters', description="所属文档"
    )
    parent = fields.ForeignKeyField(
        'models.Chapter', 
        related_name='children', 
        null=True, 
        description="父章节"
    )
    start_page = fields.IntField(description="起始页码")
    end_page = fields.IntField(description="结束页码")
    
    class Meta:
        table = "chapters"

class ChapterContent(TimestampMixin):
    """章节内容模型"""
    id = fields.IntField(pk=True)
    chapter = fields.OneToOneField(
        'models.Chapter', 
        related_name='content',
        description="所属章节"
    )
    content = fields.TextField(description="章节内容")
    raw_content = fields.TextField(description="原始内容", null=True)  # 保存PDF提取的原始文本
    processed_content = fields.TextField(description="处理后的内容", null=True)  # 经过清洗和格式化的文本
    
    class Meta:
        table = "chapter_contents" 